import {
  workOderAudit
} from '/service/service'
const {
  getCurrentStatusMap
} = require('/utils/statusMap')
Page({
  data: {
    mapV2Enable: dd.canIUse('map.optimize'),
    markers: [],
    id: null,
    info: {}
  },
  onLoad(option) {
    const {
      id
    } = option
    this.setData({
      id
    })
    this.getInfo(id)
  },
  async getInfo(id) {
    const res = await workOderAudit(id)
    console.log(res)
    const info = {
      ...res,
      statusName: getCurrentStatusMap(res.status)
    }
    this.setData({
      info
    })
    const {
      id: infoId,
      longitude,
      latitude,
      faultLocation
    } = res
    const markers = [{
      id: infoId,
      longitude,
      latitude,
      title: faultLocation,
      width: "20",
      height: "30",
      iconPath: "/images/mark_point.png",
    }]
    this.setData({
      markers
    })
    console.log(markers)
  },
  imagePreview(e) {
    const {
      url
    } = e.currentTarget.dataset
    console.log(url)
    this.previewSingleImage(url)
  },
  previewSingleImage(url) {
    dd.previewImage({
      urls: [url],
      current: url,
      success: () => {
        console.log('图片预览成功');
      },
      fail: (err) => {
        console.error('图片预览失败', err);
        dd.showToast({
          content: '预览失败，请重试',
          type: 'fail',
          duration: 2000
        });
      }
    });
  },
});